package pirate_chest;

/**
 * Author: Daniel
 * Date: 20.09.13
 */

public class PirateChest {
    private int numGold;

    public PirateChest() {
        this.numGold = 0;
    }

    public PirateChest(int numGold) {
        if (numGold < 0)
            this.numGold = 0;
        this.numGold = numGold;
    }

    public void addGold(int gold) {
        if (gold < 0)
            gold = 0;
        this.numGold += gold;
    }

    public int checkGold() {
        return numGold;
    }

    @Override
    public boolean equals(Object obj) {
        if (this.getClass() == obj.getClass()) {
            PirateChest chest = (PirateChest) obj;
            if (numGold == chest.checkGold()) {
                return true;
            }
        }
        return false;
    }

    public void removeGold(int gold) {
        if (gold > numGold)
            gold = numGold;
        else if (gold < 0)
            gold = 0;
        numGold -= gold;
    }

    @Override
    public String toString() {
        return "Chest has " + numGold + " pieces of gold";
    }
}
